/*******************************************************************************
 * Copyright (c) 2017, 2025 Lablicate GmbH.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Jan Holy - initial API and implementation
 * Philip Wenig - refactoring
 * Lorenz Gerber - improve description
 *******************************************************************************/
package org.eclipse.chemclipse.xxd.process.supplier.pca.core.preprocessing;

import java.util.List;

import org.eclipse.chemclipse.model.statistics.ISample;
import org.eclipse.chemclipse.model.statistics.ISampleData;
import org.eclipse.chemclipse.model.statistics.ISamples;
import org.eclipse.chemclipse.model.statistics.IVariable;

public class CenteringMean extends AbstractCentering {

	@Override
	public String getDescription() {

		return "In Mean centering, the mean is subtracted from each value which centeres the feature around the mean.";
	}

	@Override
	public String getName() {

		return "Mean centering";
	}

	@Override
	public <V extends IVariable, S extends ISample> void process(ISamples<V, S> samples) {

		List<V> variables = samples.getVariables();
		for(int i = 0; i < variables.size(); i++) {
			if(useVariable(samples, i)) {
				double value = getCenteringValue(samples.getSamples(), i, MEAN);
				int j = i;
				samples.getSamples().stream().forEach(s -> {
					ISampleData<?> data = s.getSampleData().get(j);
					data.setModifiedData(getData(data) - value);
				});
			}
		}
	}

	@Override
	public int getCenteringType() {

		return MEAN;
	}
}
